package com.qyhl.school.school.center.certificate;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.gyf.immersionbar.ImmersionBar;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qyhl.school.R;
import com.qyhl.school.R2;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.entity.school.SchoolCertificateBean;

import butterknife.BindView;
import butterknife.OnClick;


@Route(path = ARouterPathConstant.SCHOOL_CENTER_CERTIFICATE)
public class SchoolCenterCertificateActivity extends BaseActivity implements SchoolCenterCertificateContract.SchoolCenterCertificateView {
    @BindView(R2.id.head_icon)
    RoundedImageView headIcon;
    @BindView(R2.id.name)
    TextView name;
    @BindView(R2.id.school)
    TextView school;
    @BindView(R2.id.inst)
    TextView inst;
    @BindView(R2.id.title_layout)
    RelativeLayout titleLayout;
    private SchoolCenterCertificatePresenter mPresenter;

    private String username;

    private SchoolCertificateBean mBean;

    @Override
    protected int getContentView() {
        return R.layout.activity_school_center_certificate;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {
        mImmersionBar
                .fullScreen(true)
                .statusBarDarkFont(false)
                .navigationBarColor(R.color.transparent)
                .init();
    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        mPresenter = new SchoolCenterCertificatePresenter(this);
        username = CommonUtils.getInstance().getUserName();
//        mPresenter.getData(username);

        mBean = (SchoolCertificateBean) getIntent().getSerializableExtra("bean");
        setData(mBean);
    }

    @Override
    protected void setListener() {
        headIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBean == null) {
                    showLoading();
                    mPresenter.getData(username);
                }
            }
        });
    }

    @Override
    public void setData(SchoolCertificateBean bean) {
        mBean = bean;
        dismissLoading();
        name.setText(bean.getName());

        school.setText(bean.getSchool().getName());

        inst.setText(bean.getReporterOrgName());

        Glide.with(this)
                .load(bean.getLogo())
                .apply(new RequestOptions().placeholder(R.drawable.comment_head_default).error(R.drawable.comment_head_default))
                .into(headIcon);

    }

    @Override
    public void setError(String msg) {
        dismissLoading();
        showToast(msg);
        headIcon.setImageResource(R.drawable.comment_head_default);
    }


    @OnClick(R2.id.back_btn)
    public void onClick() {
        finish();
    }
}
